<?php
declare(strict_types=1);

namespace App\Aigc;

use App\Controller;
use Field\AigcNavConst;
use Field\AigcNavLinkConst;
use Field\SysArticleConst;
use Field\SysCateConst;

// hook controller_aigc_index_use.php

/**
 * @title   新闻动态
 * @auth    true
 * @rank    10
 */
class Index extends Controller
{
    // hook controller_aigc_index_public_start.php

    // hook controller_aigc_index_public_end.php
    protected string $name = '';

    /**
     * @title    网址导航
     * @rank    99
     */
    public function action_Nav()
    {

        $agic_nav = $this->AigcNav->select([AigcNavConst::Status => 1]);
        $agic_nav = arraylist_tree($agic_nav, AigcNavConst::AigcNavID, AigcNavConst::ParentAigcNavID);
        //获取具体的分类导航
        $allAgicLink = $this->AigcNavLink->select([
            AigcNavLinkConst::Status => 1
        ]);

        $itemOneLink = arrlist_group($allAgicLink, AigcNavLinkConst::AigcNavID);
        //LinkDesc字段是否包含img 字符串 有就给个标识
        foreach ($itemOneLink as $key => $value) {
            foreach ($value as $k => $v) {
                if (strstr($v[AigcNavLinkConst::LinkDesc], 'img')) {
                    $itemOneLink[$key][$k]['isImg'] = 1;
                } else {
                    $itemOneLink[$key][$k]['isImg'] = 0;
                }
                if(strpos($v[AigcNavLinkConst::Icon],':image')==FALSE){
                    //'https://tbone.oss-cn-shenzhen.aliyuncs.com'
                    $itemOneLink[$key][$k]['Icon']=$itemOneLink[$key][$k]['Icon'];
                }

            }
        }
        return $this->View(get_defined_vars());
    }
    /**
     * @title    首页
     * @rank    99
     */
    public function action_Index()
    {
        $catePinyin = '/' . $this->request->param('name', 'news');
        !empty($this->name) && $catePinyin = $this->name;
        $page = $this->request->param('page', 1);
        $title = [];
        $cond = [];
        $path = '/';

        if (!empty($catePinyin) && empty($this->SysCate->DataPinyin[$catePinyin])) {
            $this->response('0301', [], '分类不存在', '/', 301);
        }

        $DataCate = $this->SysCate->DataKey[$this->SysCate->DataPinyin[$catePinyin]];
        $path = $catePinyin;

        if (!empty($this->SysCate->DataSon[$DataCate['CateID']])) {
            $CateIDs = $this->SysCate->DataSon[$DataCate['CateID']];
            $CateIDs[] = $DataCate['CateID'];
            $cond[SysArticleConst::CateID] = $CateIDs;
        } else {
            $cond[SysArticleConst::CateID] = $DataCate['CateID'];
        }
        $title[] = $DataCate['Name'];
        $orderby = [SysArticleConst::ArticleID => -1];
        $List = $this->SysArticle->GetList($cond, $orderby, $page, 20);
        $page > 1 && $title[] = '第' . $page . '页';
        $List['total'] = 10000;
        $pagination = pagination("{$path}/{page}", $List['total'], $page, 20);
        return $this->View(get_defined_vars(), '@Index.Index');
    }


    /**
     * @title   详情页
     * @rank    99
     */
    public function action_Detail()
    {
        $catePinyin = '/' . $this->request->param('name', 'news');
        !empty($this->name) && $catePinyin = $this->name;
        $title = [];
        if (!empty($catePinyin) && empty($this->SysCate->DataPinyin[$catePinyin])) {
            $this->response('0301', [], '分类不存在', '/', 301);
        }
        $ArticleID = $this->request->param('ArticleID', 0);
        empty($ArticleID) && $this->response('0301', [], '内容不存在', $catePinyin, 301);
        $DataCate = $this->SysCate->DataKey[$this->SysCate->DataPinyin[$catePinyin]];
        return $this->View(get_defined_vars(), '@Index.Detail');
    }

    /**
     * @title   测试
     * @rank    99
     */
    public function action_Test(){
        $this->response('0001', [], '分类不存在 456');
    }



    // hook controller_aigc_index_end.php
}

?>